package cn.pfz.query;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;


//封装结果集的
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Setter
public class PageResult<T> {
    //    用户键入
    private int currentPage;
    private int pageSize;
    //  sql查询的
    private int totalCount;
    private List<T> data;//当前页结果集
    //    计算的
    private int prePage;
    private int nextPage;
    private int totalPage;

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;

        if(totalCount <= pageSize) { this.totalPage = 1; this.prePage = 1; this.nextPage = 1; return; }
        this.totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        this.prePage = currentPage - 1 >= 1 ? currentPage - 1 : 1;
        this.nextPage = currentPage + 1 <= totalPage ? currentPage + 1 : this.totalPage;
    }

}
